<?php

namespace common\utils;

use yii\db\ActiveQuery;

/**
 *
 */
class QueryUtil
{
    public static function applyTimeRange(ActiveQuery $query, array $params, $field = 'create_time')
    {
        if (isset($params['start_time']) && $params['start_time']) {
            $query->andFilterWhere(['>=', $field, $params['start_time'] . ' 00:00:00']);
        }
        if (isset($params['end_time']) && $params['end_time']) {
            $query->andFilterWhere(['<=', $field, $params['end_time'] . ' 23:59:59']);
        }
    }
}